import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
import HelloWorld from '@/components/HelloWorld'
import login from '@/views/login'
import notorder from '@/views/notorder'
import groups from '@/views/groups'
import classinfo from '@/views/classinfo'
import courseinfo from '@/views/courseinfo'
import favorites from '@/views/favorites'
import tiku from '@/views/onlineResource/tiku'
import video from '@/views/onlineResource/video'
import kejian from '@/views/onlineResource/kejian'
import taojuan from '@/views/onlineResource/taojuan'
import createTaojuan from '@/views/onlineResource/createTaojuan'
import playVideo from '@/views/onlineResource/playVideo'
import completeTaojuan from '@/views/onlineResource/completeTaojuan'
import homework from '@/views/homework/index'
import operatework from '@/views/homework/operatework'
import completeWork from '@/views/homework/completeWork'
import addques from '@/views/homework/addques'
import workDetail from '@/views/homework/workDetail'


Vue.use(Router)

let router=new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: login
    },
    {
      path: '/notorder',
      name: 'notorder',
      component: notorder
    },
    {
      path: '/login',
      name: 'login',
      component: login,
      meta:{
      	keepAlive:true
      }
    },
    {
      path: '/group/:index',
      name: '分组',
      component: groups,
      meta: {
        login: true,
        keepAlive:true
      }
    },
    {
      path: '/classinfo/:index',
      name: '课堂表现',
      component: classinfo,
      meta: {
        login: true,
        keepAlive:true
      }
    },
    {
      path: '/courseinfo/:timeon/:timeoff/:coursename/:lessonid/:index',
      name: '科目详情',
      component: courseinfo,
      meta: {
        login: true
      }
    },
    {
      path: '/favorites/:index',
      name: '收藏夹',
      component: favorites,
      meta: {
        login: true
      }
    },
    {
      path: '/tiku/:index',
      name: '题库',
      component: tiku,
      meta: {
        login: true
      }
    },
    {
      path: '/video/:index',
      name: '视频',
      component: video,
      meta: {
        login: true,
        keepAlive:true
      }
    },
    {
      path: '/playVideo/:vid/:index',
      name: '播放视频',
      component: playVideo,
      meta: {
        login: true
      }
    },
    {
      path: '/kejian/:index',
      name: '课件',
      component: kejian,
      meta: {
        login: true,
        keepAlive:true
      }
    },
    {
      path: '/taojuan/:index',
      name: '套卷',
      component: taojuan,
      meta: {
        login: true,
        keepAlive:true
      }
    },
    {
      path: '/createTest/:index',
      name: '创建套卷',
      component: createTaojuan,
      meta: {
        login: true
      }
    },
    {
      path: '/completeTaojuan/:courseid/:index',
      name: '创建套卷',
      component: completeTaojuan,
      meta: {
        login: true
      }
    },
    {
      path: '/homework/:index',
      name: '在线作业',
      component: homework,
      meta: {
        login: true
      }
    },
    {
      path: '/operatework/:index',
      name: '布置作业',
      component: operatework,
      meta: {
        login: true
      }
    },
    {
      path: '/workDetail/:index',
      name: '作业详情',
      component: workDetail,
      meta: {
        login: true
      }
    },
    {
      path: '/addques/:index',
      name: '添加题集',
      component: addques,
      meta: {
        login: true
      }
    },
    {
      path: '/completeWork/:courseid/:index',
      name: '题集内容',
      component: completeWork,
      meta: {
        login: true
      }
    }
    
  ]
})
router.beforeEach((to, from, next) => {
  if (to.matched.some((item) => item.meta.login)) {
    store.commit('INIT_STATE')
    if (!store.state.userlogin) {
      router.push({
        path: '/login'
      })
    } else {
      next();
    }
  } else {
    next()
  }
})

export default router
